package com.shop.controller;


import com.shop.annotation.RequireRoles;
import com.shop.entity.SupplierGoods;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import com.shop.service.SupplierGoodsService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * (SupplierGoods)表控制层
 *
 * @author makejava
 * @since 2020-11-21 10:12:56
 */
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("goods")
public class SupplierGoodsController {
    /**
     * 服务对象
     */
    private final SupplierGoodsService supplierGoodsService;

    /**
     * 商品列表
     */
    @RequireRoles(roles = {"supplier","merchant"})
    @PostMapping("getGoodsList")
    public Rsp getGoodsList(@RequestBody PageParam<SupplierGoods> pageParam,
                            @RequestHeader Integer supplierId){
        return Rsp.success(supplierGoodsService.getGoodsList(pageParam,supplierId));
    }

    /**
     * 展示商品列表
     */
    @RequireRoles(roles = {"supplier","merchant"})
    @PostMapping("showGoodsList")
    public Rsp showGoodsList(@RequestBody PageParam<SupplierGoods> pageParam){
        return Rsp.success(supplierGoodsService.showGoodsList(pageParam));
    }

    /**
     * 修改商品
     */
    @RequireRoles(roles = {"supplier"})
    @PutMapping("updateGoodsName")
    public Rsp updateGoodsName(@RequestBody SupplierGoods supplierGoods){
        return Rsp.success(supplierGoodsService.updateGoodsName(supplierGoods));
    }
    /**
     * 新增商品
     */
    @RequireRoles(roles = {"supplier"})
    @PostMapping("insertGoods")
    public Rsp insertGoods(@RequestBody SupplierGoods supplierGoods,@RequestHeader Integer supplierId){
        supplierGoods.setSupplierId(supplierId);//供应商id
        return Rsp.success(supplierGoodsService.insertGoods(supplierGoods));
    }

    /**
     * 删除商品
     *
     */
    @RequireRoles(roles = {"supplier"})
    @PutMapping("delGoods")
    public Rsp delGoods(@RequestBody SupplierGoods supplierGoods){
        return Rsp.success(supplierGoodsService.delGoods(supplierGoods.getId()));
    }


    /**
     * 过商品类别id查询该商户下所有商品
     * @param CategoryId
     * @return
     */
    @RequireRoles(roles = {"supplier"})
    @GetMapping("getGoodsListByCategoryId")
    public Rsp getGoodsListByCategoryId(String CategoryId)
    {
        System.out.println(CategoryId);
        return Rsp.success(supplierGoodsService.getGoodsListByCategoryId(CategoryId));
    }


}
